<?php
namespace app\common\model;
class SmsLog extends Common {
	protected $insert = ['sendtime' => SYS_TIME];
	public function addLog($phone, $code) {
		return $this->save(['phone' => $phone, 'code' => $code]);
	}
	public function checkSms($phone, $code) {
		$isCount = $this->where("phone", $phone)->where("code", $code)->count();
		if (!$isCount) {
			return "验证码输入错误！";
		}
		if ($isCount) {
			$sendtime = $this->where("phone", $phone)->where("code", $code)->value("sendtime");
			if (SYS_TIME - $sendtime > 300) {
				return "验证码失效！";
			}
		}
		$this->where("phone", $phone)->where("code", $code)->delete();
		return true;
	}
	public function checkSendSms($phone) {
		$isCount = $this->where("phone", $phone)->count();
		if ($isCount) {
			$sendtime = $this->where("phone", $phone)->order("id desc")->value("sendtime");
			if (SYS_TIME - $sendtime <= 300) {
				return false;
			}
		}
		return true;
	}
}